/**
 * Created by udi on 2016/11/26.
 */
'use strict'
const fs = require('fs');
const os = require('os');
const path = require('path');

// 获取临时文件夹路径
const tmpDir = os.tmpdir();
const {execSync} = require('child_process');

const exec = curlText => {
    // var fileName = path.resolve(tmpDir,"curl-" + Date.now() + ".sh")
    var txt = curlText.replaceAll("--insecure", " ")
        .replaceAll("\r\n","\n")
        .replace("\r","\n");

    // fs.writeFileSync(fileName, txt,"utf-8");

    logger.info(txt);

    var output = "";
    try {
        output = execSync(txt).toString()
    } catch (e) {
        if ("message" in e) {
            output = e.message;
        } else if (e.getJsType() == "string") {
            output = e;
        } else {
            output = JSON.stringify(e);
        }
    }

    return output;
}

module.exports.exec = exec;
